var imgSrc = []; //图片路径

var imgFile = []; //文件流

var imgName = []; //图片名字

//选择图片
function imgUpload1(obj) {
	var oInput = '#' + obj.inputId;
	var imgBox = '#' + obj.imgBox;

	$(oInput).on("change", function() {

		var fileImg = $(oInput)[0];
		var fileList = fileImg.files;
		var isManyFile = $(oInput)[0]['multiple'];

		if(isManyFile === true){

			imgSrc.splice(0,imgSrc.length);
			imgName.splice(0,imgSrc.length);
			imgFile.splice(0,imgSrc.length);

			for(var i = 0; i < fileList.length; i++) {
				var imgSrcI = getObjectURL(fileList[i]);
				imgName.push(fileList[i].name);
				imgSrc.push(imgSrcI);
				imgFile.push(fileList[i]);
			}

			$(imgBox).html('');
			imgBox = $(imgBox);
			var html = '';

			for(var a = 0; a < imgSrc.length; a++) {
				html += '<div class="imgContainer"><img title=' + imgName[a] + ' alt=' + imgName[a] + ' src=' + imgSrc[a] + ' onclick="imgDisplay(this)"></div>';
			}

			$(imgBox).append(html);

		}else if(isManyFile === false){

			var imgSrcI = getObjectURL(fileList[0]);
			imgName = (fileList[0].name);
			imgSrc = (imgSrcI);
			imgFile = (fileList[0]);
			imgBox = $(imgBox);

			imgBox.html('<div class="imgContainer"><img title=' + imgName + ' alt=' + imgName + ' src=' + imgSrc + ' onclick="imgDisplay(this)"></div>');
		}
	});
}

//图片灯箱
function imgDisplay1(obj) {
	var src = $(obj).attr("src");
	var imgHtml = '<div style="width: 100%;height: 100vh;overflow: auto;background: rgba(0,0,0,0.5);text-align: center;position: fixed;top: 0;left: 0;z-index: 1000;"><img src=' + src + ' style="margin-top:100px;width:70%;margin-bottom:100px;"/><p style="font-size: 50px;position: fixed;top: 30px;right: 30px;color: white;cursor: pointer;" onclick="closePicture(this)">×</p></div>';
	$('body').append(imgHtml);
}

//关闭
function closePicture1(obj) {
	$(obj).parent("div").remove();
}

//图片预览路径
function getObjectURL1(file) {
	var url = null;
	if(window.createObjectURL != undefined) { // basic
		url = window.createObjectURL(file);
	} else if(window.URL != undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file);
	} else if(window.webkitURL != undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file);
	}
	return url;
}